package com.atguigu.dga.meta.mapper;

import com.atguigu.dga.meta.bean.TableMetaInfo;
import com.atguigu.dga.meta.bean.TableMetaInfoVO;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 元数据表 Mapper 接口
 * </p>
 *
 * @author zhangchen
 * @since 2023-06-27
 */
@Mapper
@DS("dga")
public interface TableMetaInfoMapper extends BaseMapper<TableMetaInfo> {


    @Select("${sql}")
    public List<TableMetaInfoVO> selectTableMetaListPage(@Param("sql") String sql);


    @Select("${sql}")
    public Integer selectTableMetaCount(@Param("sql") String sql);

    //字段多，装配麻烦  // 1 把后面join的表 与前面表同名但不同值的字段重命名
    //2 有嵌套结构的 没有办法通过注解的方式装备 ，需要借助xml
    @Select(" select  te.id as te_id, te.create_time as te_create_time  ,tm.*,te.* from table_meta_info tm join table_meta_info_extra te " +
            " on tm.table_name =te.table_name and tm.schema_name=te.schema_name  " +
            " where tm.assess_date= #{assessDate}")
    @ResultMap("meta_map")  //结果映射  编写xml
    public List<TableMetaInfo> selectTableMetaAllList(@Param("assessDate") String assessDate);
}
